package org.uni.cil.mail;

import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Store;

import java.util.HashMap;
import java.util.Properties;

/**
 * @author Christian
 * 
 */
public class MailConnector {
	Store store;

	MailConnector(HashMap<String, String> AccessData) {

		String host = AccessData.get("hostname");
		String hostType = AccessData.get("hostType");
		String username = AccessData.get("username");
		String password = AccessData.get("password");

		// Create empty properties
		Properties props = new Properties();

		// Get session
		Session session = Session.getDefaultInstance(props, null);

		// Get the store
		Store mailStore = null;
		try {
			mailStore = session.getStore(hostType);
		} catch (NoSuchProviderException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// Connect to store
		try {
			mailStore.connect(host, username, password);
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		store = mailStore;
	}
}
